/**
 * 2016，thor.com，all rights reserved。
 * 
 * Project：		palmmall-core
 * Filename：	AStoreQueryParamConverter.java
 * Created：		2016年9月5日
 * Creator：		wolv
 */
package com.thor.palmmall.rest.complaint.converter;

import java.util.ArrayList;
import java.util.HashMap;

import org.springframework.core.convert.converter.Converter;

import com.thor.commons.entity.KV;
import com.thor.palmmall.rest.common.AQueryCommonParam;
import com.thor.palmmall.spi.common.SQueryContractParam;

/**
 * @author wolv
 *
 */
public class SComplaintQueryParamConverter
    implements Converter<AQueryCommonParam, SQueryContractParam> {

  public static SComplaintQueryParamConverter getInstance() {
    if (instance == null)
      instance = new SComplaintQueryParamConverter();
    return instance;
  }

  private static SComplaintQueryParamConverter instance;

  private SComplaintQueryParamConverter() {
  }

  @Override
  public SQueryContractParam convert(AQueryCommonParam source) {
    if (source == null)
      return null;

    SQueryContractParam target = new SQueryContractParam();
    target.setPage(source.getPage());
    target.setPageSize(source.getPageSize());
    target.setStores(new ArrayList<String>());
    target.setKeyword(source.getKeyword());
    target.setState(source.getState());
    target.setBeginTime(source.getBeginTime());
    target.setEndTime(source.getEndTime());
    target.setParams(source.getParams()!=null?source.getParams():new HashMap<String,Object>());
    if (source.getStores() != null)
      target.getStores().addAll(source.getStores());
    target.setUserGroups(new ArrayList<KV>());
    if (source.getUserGroups() != null)
      target.getUserGroups().addAll(source.getUserGroups());
//    target.setOrder(source.getOrder());
    return target;
  }

}
